#--- loading ---#
library(scRNAseq)
library(scater)
sce.416b <- LunSpikeInData(which = "416b")
sce.416b$block <- factor(sce.416b$block)

location <- rowRanges(sce.416b)
is.mito <- any(seqnames(location) == "MT")

sce.416b <- addPerCellQC(sce.416b, subsets = list(Mito = is.mito))
colnames(colData(sce.416b))

qc.lib2 <- isOutlier(df$sum, log = TRUE, type = "lower")
qc.nexprs2 <- isOutlier(df$detected, log = TRUE, type = "lower")
qc.spike2 <- isOutlier(df$altexps_ERCC_percent, type = "higher")
qc.mito2 <- isOutlier(df$subsets_Mito_percent, type = "higher")
# The same as above qc.XXX
reasons <- quickPerCellQC(df, sub.fields = c("subsets_Mito_percent", "altexps_ERCC_percent"))

batch <- paste0(sce.416b$phenotype, "-", sce.416b$block)
batch.reasons <- quickPerCellQC(df,
  batch = batch,
  sub.fields = c("subsets_Mito_percent", "altexps_ERCC_percent")
)
colSums(as.matrix(batch.reasons))

